import request from '@/utils/request'

// 管理员登录
export function login(data: {
  account: string
  password: string
}) {
  const formData = new FormData()
  formData.append('account', data.account)
  formData.append('password', data.password)
  
  return request({
    url: '/admin/login',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 获取用户列表
export function getUserList() {
  return request({
    url: '/app/manage',
    method: 'get'
  })
}

// 添加用户
export function addUser(data: {
  CusName: string
  CusPhone: string
  CusSex: string
  CusAccount: string
  CusPassword: string
}) {
  const formData = new FormData()
  formData.append('CusName', data.CusName)
  formData.append('CusPhone', data.CusPhone)
  formData.append('CusSex', data.CusSex)
  formData.append('CusAccount', data.CusAccount)
  formData.append('CusPassword', data.CusPassword)

  return request({
    url: '/app/manage',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 修改用户信息
export function updateUser(data: {
  CusId: string
  CusName?: string
  CusPhone?: string
  CusSex?: string
  CusAccount?: string
  CusPassword?: string
}) {
  const formData = new FormData()
  formData.append('CusId', data.CusId)
  if (data.CusName) formData.append('CusName', data.CusName)
  if (data.CusPhone) formData.append('CusPhone', data.CusPhone)
  if (data.CusSex) formData.append('CusSex', data.CusSex)
  if (data.CusAccount) formData.append('CusAccount', data.CusAccount)
  if (data.CusPassword) formData.append('CusPassword', data.CusPassword)

  return request({
    url: '/app/manage',
    method: 'put',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 删除用户
export function deleteUser(CusId: string) {
  return request({
    url: `/app/manage/${CusId}`,
    method: 'delete'
  })
} 